package com.xinzhi.dao.impl;

import com.xinzhi.dao.IBookDao;
import com.xinzhi.entiey.Book;

import java.util.List;

public class ChooseUtil {
    int count = -1;
    public void add(){
        IBookDao iBookDao = new BookDaoImpl();
        Book book = new Book();
        book.setBookid(6);
        book.setLb("搞怪");
        book.setCbs("szggs");
        book.setZz("qyl");
        book.setName("怪到你无语");
        book.setPice("25");
        count = iBookDao.addBook(book);
        System.out.println(count>0?"成功":"失败");
    }
    public void delete(){
        IBookDao iBookDao = new BookDaoImpl();
        Book book = new Book();
        count = iBookDao.deleteBook(6);
        System.out.println(count>0?"成功":"失败");
    }
    public void update(){
        IBookDao iBookDao = new BookDaoImpl();
        Book book = new Book();
        book.setBookid(5);
        book.setLb("nbb");
        book.setCbs("lbb");
        book.setZz("sbb");
        book.setName("hbb");
        book.setPice("56");
        int count = iBookDao.updateBook(book);
        System.out.println(count>0?"修改成功":count==0?"未修改":"修改失败");
    }
    public void getAll(){
        IBookDao iBookDao = new BookDaoImpl();
        List<Book> books = iBookDao.getAll();
        for (Book book:books) {
            System.out.println(book.getLb()+"-----"+book.getCbs());
        }
    }
    public void getBookById(){
        IBookDao iBookDao = new BookDaoImpl();
        Book book =iBookDao.getBookId(2);
        System.out.println(book.getBookid()+"-----"+book.getName());

    }

}
